<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Models\Address;
use App\Repositories\AddressRepo;


class AddressController extends ApiBaseController
{
    public function create(Request $request)
    {
        $input = $request->only(['name','mobile','province','city','area','detail','door','default']);

        $user_id = $this->getUserId();
        $input['user_id'] = $user_id;
        $repo = new AddressRepo();
        $repo->create($input);
        return $this->sucRes();
    }

     public function update(Request $request)
    {
        $id = $request->id;
        $input = $request->only(['name','mobile','province','city','area','detail','door','default']);
        $user_id = $this->getUserId();
        $input['user_id'] = $user_id;
        $repo = new AddressRepo();
        $repo->update($user_id,$id,$input);
        return $this->sucRes();
    }
     public function del(Request $request)
    {
        $id = $request->id;
        $user_id = $this->getUserId();
        $repo = new AddressRepo();
        $repo->del($id,$user_id);
        return $this->sucRes();
    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function userAddr()
    {
       $user_id = $this->getUserId();
        $repo = new AddressRepo();
        return $this->sucRes(200,$repo->getDefault($user_id));
    }
    public function userAddrList()
    {
        $user_id = $this->getUserId();
        $repo = new AddressRepo();
        return $this->sucRes(200,$repo->getList($user_id,[],15));
    }
}